package com.jiemengshi.server.util;

import com.alibaba.fastjson.JSONObject;

import java.io.PrintWriter;
import java.io.StringWriter;

public class PrjException extends Exception {
	/**
	 * 
	 */
	private static final long serialVersionUID = 7338309253128126819L;
	private int errCode;
	private String errMsg;
	
	public PrjException(int errCode){
		this.errCode = errCode;
		this.errMsg = ErrorCodeMsg.getErrorMsg(errCode);
	}
	
	public PrjException(int errCode, String errMsg){
		this.errCode = errCode;
		this.errMsg = errMsg;
	}
	
	public int getErrCode() {
		return errCode;
	}

	public void setErrCode(int errCode) {
		this.errCode = errCode;
	}

	public String getErrMsg() {
		return errMsg;
	}

	public void setErrMsg(String errMsg) {
		this.errMsg = errMsg;
	}

	public String toString(){
		JSONObject ret = new JSONObject();
		
		ret.put("errCode", errCode);
		ret.put("errMsg", errMsg);
		
		return ret.toJSONString();
	}
	
	public static String getTrace(Throwable e) {
        StringWriter stringWriter= new StringWriter();
        PrintWriter writer= new PrintWriter(stringWriter);
        e.printStackTrace(writer);
        StringBuffer buffer= stringWriter.getBuffer();
        return buffer.toString();
    }
}
